Crate unix_mode

source ·
Expand description

Manipulate Unix file mode bits.

Every filesystem entry (or inode) on Unix has a bit field of mode bits that describe both the type of the file and its permissions.

These are classically displayed in the left of ls output, and the permissions can be changed with chmod. For example:

assert_eq!(unix_mode::to_string(0o0040755), "drwxr-xr-x");
assert_eq!(unix_mode::to_string(0o0100640), "-rw-r-----");

The encoding is fairly standard across unices, and occurs in some file formats and network protocols that might be seen on non-Unix platforms, including that of rsync.

This library isn’t Unix-specific and doesn’t depend on the underlying OS to interpret the bits.

For example, this can be used with the return value from std::os::unix::fs::MetadataExt::mode.

The names of the predicate functions match std::fs::FileType and std::os::unix::fs::FileTypeExt.

Changelog

0.1.4

0.1.3

  • Add Type enum for matching the file type.
  • Add Access, and Accessor enums for testing permissions.
  • More tests.
  • Move changelog into Rustdoc.

0.1.2

0.1.1

  • Fix tests on Windows.

0.1.0

  • Initial release.

Enums

Functions

  • Check whether mode represents an allowed (true) or denied (false) access
  • Returns true if this mode represents a block device.
  • Returns true if this mode represents a character device.
  • Returns true if this mode represents a directory.
  • Returns true if this mode represents a fifo, also known as a named pipe.
  • Returns true if this mode represents a regular file.
  • Returns true if the set-group-ID bit is set
  • Returns true if the set-user-ID bit is set
  • Returns true if this mode represents a Unix-domain socket.
  • Returns true if the sticky bit is set
  • Returns true if this mode represents a symlink.
  • Convert Unix mode bits to a text string describing type and permissions, as shown in ls.